<?php

namespace app\index\controller\train;

use addons\shop\model\TrainEnroll;
use app\common\controller\Frontend;
use think\Db;

class Index extends Frontend
{
    protected $layout      = 'default';
    protected $noNeedLogin = [];
    protected $noNeedRight = ['*'];

    public function index()
    {
        $list = TrainEnroll::where('uid', $this->auth->id)->paginate(10)->each(function (&$item) {
            $item            = $item->toArray();
            $item['article'] = Db::name("train_article")->where(['id' => $item['article_id']])->find();
            return $item;
        });
        $this->view->assign('u_type', 4);
        return $this->fetch('', [
            'list'   => $list,
            'u_type' => 4
        ]);
    }

    /**
     * 站内信
     */
    public function mail()
    {
        $user_id   = $this->auth->id;
        $mail_data = Db::name("mail")->where(['uid' => $user_id])->select();
        $this->view->assign('data', $mail_data);
        $this->view->assign('title', '我的订单');
        $this->view->assign('u_type', 10);
        return $this->view->fetch();
    }
}
